﻿using MyUAMS.BLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class MaintenanceMgm_BRMgm : System.Web.UI.Page
{
    AdminServer adminSrv = new AdminServer();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
        }
    }

    protected void btnOK_Click(object sender, EventArgs e)
    {
        
        int uid;
        DateTime date;
        int apid = 0;
        int aid = 0;
        string type = "";
        int amount = 0;
        int step = 0;
        int apuid = 0;
        string apuname = "";
        string status = "";
        GridView gvProduct = new GridView();
        gvProduct = (GridView)Page.FindControl("dgvAdmin");
        if (gvProduct != null)
        {
            for (int i = 0; i < gvProduct.Rows.Count; i++)
            {
                CheckBox chkChoice = new CheckBox();
                chkChoice = (CheckBox)gvProduct.Rows[i].FindControl("Choice");
                if (chkChoice != null)
                {
                    if (chkChoice.Checked)
                    {
                        uid = int.Parse(gvProduct.Rows[i].Cells[7].Text);
                        
                        
                        
                        apid = int.Parse(gvProduct.Rows[i].Cells[1].Text);
                        
                        aid = int.Parse(gvProduct.Rows[i].Cells[2].Text);
                        amount = int.Parse(gvProduct.Rows[i].Cells[5].Text);
                        type = gvProduct.Rows[i].Cells[4].Text;
                        step = int.Parse(gvProduct.Rows[i].Cells[9].Text);
                        status = gvProduct.Rows[i].Cells[13].Text;
                        
                        if (Session["AminId"] != null && Session["AdminName"] != null)
                        {
                            apuid = (int)Session["AminId"];
                            apuname = Session["AdminName"].ToString();
                            adminSrv.UpdateAP(apid, aid, type, amount, step, apuid, apuname, status, uid);
                            lblProErr.Text = "审核成功";

                            Bind();
                        }
                        else
                        {
                            lblProErr.Text = "会话信息丢失";
                            
                        }



                    }
                }
            }
        }
        
    }

    protected void btnNO_Click(object sender, EventArgs e)
    {
        int uid;
        DateTime date;
        int apid = 0;
        int aid = 0;
        string type = "";
        int amount = 0;
        int step = 0;
        int apuid = 0;
        string apuname = "";
        string status;
        GridView gvProduct = new GridView();
        gvProduct = (GridView)Page.FindControl("dgvAdmin");
        if (gvProduct != null)
        {
            for (int i = 0; i < gvProduct.Rows.Count; i++)
            {
                CheckBox chkChoice = new CheckBox();
                chkChoice = (CheckBox)gvProduct.Rows[i].FindControl("Choice");
                if (chkChoice != null)
                {
                    if (chkChoice.Checked)
                    {
                        uid = int.Parse(gvProduct.Rows[i].Cells[7].Text);
                        
                        apid = int.Parse(gvProduct.Rows[i].Cells[1].Text);
                        aid = int.Parse(gvProduct.Rows[i].Cells[2].Text);
                        amount = int.Parse(gvProduct.Rows[i].Cells[5].Text);
                        type = gvProduct.Rows[i].Cells[4].Text;
                        step = int.Parse(gvProduct.Rows[i].Cells[9].Text);
                        status = "打回";
                        if (Session["AminId"] != null && Session["AdminName"] != null)
                        {
                            apuid = (int)Session["AminId"];
                            apuname = Session["AdminName"].ToString();
                            adminSrv.UpdateAP(apid, aid, type, amount, step, apuid, apuname, status, uid);
                            lblProErr.Text = "打回成功";
                            Bind();
                        }
                        else
                        {
                            lblProErr.Text = "会话信息丢失";
                            
                        }




                    }
                }
            }
        }
        
    }

    protected void btnOne_Click(object sender, EventArgs e)
    {
        var products = adminSrv.GetOneAP(1);
        if (products.Count() == 0)
        {
            lblProErr.Text = "没有需要审核的申请。";
        }
        else
        {
            lblProErr.Text = " ";
        }
        dgvAdmin.DataSource = adminSrv.GetOneAP(1);
        dgvAdmin.DataBind();
    }

    protected void btnTwe_Click(object sender, EventArgs e)
    {
        var products = adminSrv.GetTweAP(1);
        if (products.Count() == 0)
        {
            lblProErr.Text = "没有需要审核的申请。";
        }
        else
        {
            lblProErr.Text = " ";
        }
        dgvAdmin.DataSource = adminSrv.GetTweAP(1);
        dgvAdmin.DataBind();
    }

    protected void btnThree_Click(object sender, EventArgs e)
    {
        var products = adminSrv.GetThreeAP(1);
        if (products.Count() == 0)
        {
            lblProErr.Text = "没有需要审核的申请。";
        }
        else
        {
            lblProErr.Text = " ";
        }
        dgvAdmin.DataSource = adminSrv.GetThreeAP(1);
        dgvAdmin.DataBind();
    }

    protected void btnReset_Click(object sender, EventArgs e)
    {
        Bind();
    }
    protected void Bind()
    {
        var products = adminSrv.GetAllAP(1);
        if (products.Count() == 0)
        {
            lblProErr.Text = "没有需要审核的申请。";
        }
        else
        {
            lblProErr.Text = " ";
        }
        dgvAdmin.DataSource = adminSrv.GetAllAP(1);
        dgvAdmin.DataBind();
    }

}